<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="keywords" content="">
	<meta name="description" content="">
	<link href="<?php echo site_url(); ?>favicon.ico" rel="icon" type="image/x-icon" />
	<title>账号管理</title>
	 <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/css/common.css" />
	  <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/js/themes/bootstrap/easyui.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/js/themes/icon.css" />

  <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/jquery.min.js"></script>
  <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/locale/easyui-lang-zh_CN.js"></script>

	<script type="text/javascript">
		var url;
		function newUser(){
			$('#dlg').dialog('open').dialog('setTitle','新增用户账号');
			$('#fm').form('clear');
			url = 'adddb';
		}
		function editUser(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				$('#dlgedit').dialog('open').dialog('setTitle','编辑用户账号');
				$('#fmedit').form('load',row);
				url = 'edit?id='+row.id;
			}
		}
		function saveUser(){
			$('#fm').form('submit',{
				url: url,
				onSubmit: function(){
					return $(this).form('validate');
				},
				success: function(result){
					var result = eval('('+result+')');
					if (result.success){
						$('#dlg').dialog('close');		// close the dialog
						$('#dg').datagrid('reload');	// reload the user data
					} else {
						$.messager.show({
							title: 'Error',
							msg: result.msg
						});
					}
				}
			});
		}

		function saveeditUser(){
			$('#fmedit').form('submit',{
				url: url,
				onSubmit: function(){
					return $(this).form('validate');
				},
				success: function(result){
					var result = eval('('+result+')');
					if (result.success){
						$('#dlgedit').dialog('close');		// close the dialog
						$('#dg').datagrid('reload');	// reload the user data
					} else {
						$.messager.show({
							title: 'Error',
							msg: result.msg
						});
					}
				}
			});
		}
		function removeUser(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				$.messager.confirm('确认','你确定要删除这个用户？',function(r){
					if (r){
						$.post('del',{id:row.id},function(result){
							if (result.success){
								$('#dg').datagrid('reload');	// reload the user data
							} else {
								$.messager.show({	// show error message
									title: 'Error',
									msg: result.msg
								});
							}
						},'json');
					}
				});
			}
		}
	</script>
</head>
<body>
	<h2 class="navfont">用户账号管理:</h2>


	<table id="dg" title="" class="easyui-datagrid" style="width:1100px;height:550px"
			url="get_root"
			toolbar="#toolbar" pagination="true"
			rownumbers="true" fitColumns="true" singleSelect="true">
		<thead>
			<tr>


				<th field="id" width="50">编号</th>
				<th field="realname" width="50">姓名</th>
				<th field="phone" width="50">电话</th>
				<th field="depart" width="50">所属部门</th>
				<th field="username" width="50">登录名</th>
				<th field="passwd" width="50">登录密码</th>
				<th field="role_name" width="50">所属用户组</th>
				<th field="role_id" width="0" ></th>
			</tr>
		</thead>
	</table>
	<div id="toolbar">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新增</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">编辑</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeUser()">删除</a>
	</div>

	<div id="dlg" class="easyui-dialog" style="width:800px;height:350px;padding:10px 20px"
			closed="true" buttons="#dlg-buttons">
		<div class="ftitle"><h4>新增用户信息</h4></div>
		<form id="fm" method="post" novalidate>
          <table>
          	<tr>
          		<td>
	<label>用户姓名:</label>
          		</td>
							<td>
								<div class="fitem">

									<input name="realname" class="easyui-validatebox" required="true">
								</div>
							</td>
          	</tr>

						<tr>
          		<td>
	<label>联系电话:</label>
          		</td>
							<td>
								<div class="fitem">

									<input name="phone" class="easyui-validatebox" required="true">
								</div>
							</td>
          	</tr>


						<tr>
          		<td>
		<label>所属部门:</label>
          		</td>
							<td>
								<div class="fitem">

									 <input class="easyui-combotree input-normal control-text" type="text" name="depart" data-options="url:'<?php  echo site_url();?>index.php/depart/get_depart',method:'get'">
								</div>
							</td>
          	</tr>

						<tr>
          		<td>
	<label>登录名称:</label>
          		</td>
							<td>
								<div class="fitem">

									<input name="username" class="easyui-validatebox" required="true">
								</div>
							</td>
          	</tr>


						<tr>
          		<td>
	<label>登录密码:</label>
          		</td>
							<td>
								<div class="fitem">

									<input name="passwd" type="password" class="easyui-validatebox" required="true">
								</div>
							</td>
          	</tr>

						<tr>
          		<td>
<label>密码确认:</label>
          		</td>
							<td>
								<div class="fitem">

									<input name="passwdagain" type="password" class="easyui-validatebox" required="true">
								</div>
							</td>
          	</tr>


						<tr>
          		<td>
	<label>所属用户组:</label>
          		</td>
							<td>
								<div class="fitem">

											 <select  data-rules="{required:true}"  name="role_id" class="input-normal">
													<option value="">请选择...</option>
													<?php
													foreach ($roles as $key => $value) {
														?>
																<option value="<?php echo $value['id'] ?>"><?php echo $value['name'] ?></option>

														<?php
													}

													?>
												</select>
								</div>
							</td>
          	</tr>
          </table>
		</form>
	</div>



	<div id="dlgedit" class="easyui-dialog" style="width:800px;height:350px;padding:10px 20px"
			closed="true" buttons="#dlg-buttons-edit">
		<div class="ftitle"><h4>新增用户信息</h4></div>
		<form id="fmedit" method="post" novalidate>
          <table>
          	<tr>
          		<td>
	<label>用户姓名:</label>
          		</td>
							<td>
								<div class="fitem">

									<input name="realname" class="easyui-validatebox" required="true">
								</div>
							</td>
          	</tr>

						<tr>
          		<td>
	<label>联系电话:</label>
          		</td>
							<td>
								<div class="fitem">

									<input name="phone" class="easyui-validatebox" required="true">
								</div>
							</td>
          	</tr>


						<tr>
          		<td>
		<label>所属部门:</label>
          		</td>
							<td>
								<div class="fitem">

									 <input class="easyui-combotree input-normal control-text" type="text" name="depart" data-options="url:'<?php  echo site_url();?>index.php/depart/get_depart',method:'get'">
								</div>
							</td>
          	</tr>

						<tr>
          		<td>
	<label>登录名称:</label>
          		</td>
							<td>
								<div class="fitem">

									<input name="username" class="easyui-validatebox" required="true">
								</div>
							</td>
          	</tr>


						<tr>
          		<td>
	<label>登录密码:</label>
          		</td>
							<td>
								<div class="fitem">

									<input name="passwd" type="password" class="easyui-validatebox" required="true">
								</div>
							</td>
          	</tr>


						<tr>
          		<td>
	<label>所属用户组:</label>
          		</td>
							<td>
								<div class="fitem">

											 <select  data-rules="{required:true}"  name="role_id" class="input-normal">
													<option value="">请选择...</option>
													<?php
													foreach ($roles as $key => $value) {
														?>
																<option value="<?php echo $value['id'] ?>"><?php echo $value['name'] ?></option>

														<?php
													}

													?>
												</select>
								</div>
							</td>
          	</tr>
          </table>
		</form>
	</div>



	<div id="dlg-buttons-edit">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveeditUser()">保存</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgedit').dialog('close')">取消</a>
	</div>

	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">保存</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
	</div>
</body>
</html>
